home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: R.Ghosh-Roy@brunel.ac.uk (R Ghosh-Roy)
- Newsgroups: comp.lang.c,comp.lang.c.moderated
- Subject: Multiple Indirection (Pointer Arithmatic)
- Date: 23 Mar 1996 00:43:28 -0600
- Organization: Brunel University, Uxbridge, UK
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4j06ig$7q8@solutions.solon.com>
- Reply-To: R.Ghosh-Roy@brunel.ac.uk
- NNTP-Posting-Host: solutions.solon.com
-
-
- I am a bit confused about "pointer arithmatic" and therefore would appreciate
- your expert help. The following is the problem:
-
- I have three arrays (A,B,C) of structures and each structure has its own set
- of fields. In structure A, one particular field Ab points to structure B. B
- has a field Bc which points to C and C has a field named Cd. I need to look
- for Cd for each A. Can I use some kind of clever pointer arithmatic to get
- to Cd for each A? Or, is there a cleverer way?
-
- Note: 3 arrays of structures A,B and C and only one field relates elements
- of each array, ie, Ab relates to an element within an array of Bs and
- Bc relates to an element within an array of Cs. These are dynamically
- assigned.
-
- struct A
- |--------|
- | |
- | |
- | |
- | | struct B
- | Ab ---|------->|--------|
- | | | |
- |--------| | |
- | |
- | |
- | | struct C
- | Bc ---|-------->|----------|
- | | | |
- | | | |
- | | | |
- |--------| | |
- | |
- | Cd |
- | |
- | |
- | |
- | |
- |----------|
-
- I was thinking of using sizeof and offsetof expressions.
-
- Thanks,
-
- Rana
-
-
- --
- R. Ghosh-Roy @ BIPS -- R.Ghosh-Roy@brunel.ac.uk -- Extension 2772
-